//
//  YDContactExperienceCell.m
//  IngCard
//
//  Created by kf on 2017/10/18.
//  Copyright © 2017年 IngDan. All rights reserved.
//

#import "YDContactExperienceCell.h"



@implementation YDContactExperienceCellModel
-(Class) viewClass
{
    return [YDContactExperienceCell class];
}

@end


@interface YDContactExperienceCell()
@property(nonatomic, strong) UILabel *occupationLabel;//职位
@property(nonatomic, strong) UILabel *companylabel;//公司
@property(nonatomic, strong) UILabel *timeLabel;
@property(nonatomic, strong) UIImageView *thumbnail;
@property(nonatomic, strong) UIView *lineView;
@end

@implementation YDContactExperienceCell


+(CGFloat)viewHeight:(YDContactExperienceCellModel *) dataSource
{
    return dataSource.height ?:  60;
}

- (void) initSubviews
{
    [super initSubviews];
    [self.contentView addSubview:self.occupationLabel];
    [self.occupationLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(20);
        make.top.equalTo(10);
    }];
    
    [self.contentView addSubview:self.companylabel];
    [self.companylabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.occupationLabel);
        make.top.equalTo(self.occupationLabel.mas_bottom).offset(2);
    }];
    
    [self.contentView addSubview:self.timeLabel];
    [self.timeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.occupationLabel);
        make.top.equalTo(self.companylabel.mas_bottom).offset(2);
    }];
    
    [self.contentView addSubview:self.thumbnail];
    [self.thumbnail makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(-20);
        make.top.equalTo(12);
        make.width.equalTo(36);
        make.height.equalTo(36);
    }];
    
    [self.contentView addSubview:self.lineView];
    [self.lineView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(0);
        make.width.equalTo(SCREEN_WIDTH);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-1);
        make.height.equalTo(1);
    }];
}

-(void) onViewModelChanged
{
    YDContactExperienceCellModel *dataSource = (YDContactExperienceCellModel *)self.dataSource;
    if (dataSource)
    {
        self.occupationLabel.text = dataSource.occupation;
        self.companylabel.text = dataSource.company;
        self.timeLabel.text = dataSource.timer;
        
        if(dataSource.image)
        {
            self.thumbnail.image = UIImageMake(@"Contact_detail_thumbnail");
        }
        else
        {
            self.thumbnail.image = nil;// UIImageMake(@"Contact_detail_thumbnail");
        }
        
        [self.occupationLabel sizeToFit];
        [self.companylabel sizeToFit];
        [self.timeLabel sizeToFit];
    }
}


#pragma mark - lazy load
-(UILabel *) occupationLabel
{
    if (!_occupationLabel)
    {
        _occupationLabel = [UILabel new];
        _occupationLabel.text = @"Experience";
        _occupationLabel.textAlignment = NSTextAlignmentLeft;
        _occupationLabel.font = UIMediumFontMake(11);
        _occupationLabel.textColor = UIColorMake(3, 3, 3);
    }
    return _occupationLabel;
}

-(UILabel *) companylabel
{
    if (!_companylabel)
    {
        _companylabel = [UILabel new];
        _companylabel.text = @"Experience";
        _companylabel.textAlignment = NSTextAlignmentLeft;
        _companylabel.font = UIThinFontMake(9);
        _companylabel.textColor = UIColorMake(3, 3, 3);
    }
    return _companylabel;
}

-(UILabel *) timeLabel
{
    if (!_timeLabel)
    {
        _timeLabel = [UILabel new];
        _timeLabel.text = @"Experience";
        _timeLabel.textAlignment = NSTextAlignmentLeft;
        _timeLabel.font = UIRegularFontMake(8);
        _timeLabel.textColor = UIColorMake(3, 3, 3);
    }
    return _timeLabel;
}

-(UIImageView *)thumbnail
{
    if (!_thumbnail)
    {
        _thumbnail = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 36, 36)];
        _thumbnail.image = UIImageMake(@"Contact_detail_thumbnail");
        _thumbnail.layer.cornerRadius = 18;
        _thumbnail.layer.masksToBounds = YES;
        _thumbnail.contentMode = UIViewContentModeScaleToFill;
        [_thumbnail sizeToFit];
    }
    return _thumbnail;
}

- (UIView *) lineView
{
    if (!_lineView)
    {
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 123, 1)];
        _lineView.backgroundColor = UIColorMake(221, 221, 221);
    }
    return _lineView;
}
@end
